package com.llf.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class ControllerLogin {
    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session){
        if (!StringUtils.isEmpty(username) &&"123456".equals(password))
        {
            session.setAttribute("user",username);
            model.addAttribute("user",username);
            return "redirect:/main";
        }else {
            model.addAttribute("msg","账号或密码错误");
            return "index";
        }

    }
    @RequestMapping("/out")
    public String out(HttpSession session){
        session.removeAttribute("user");
        return "index";

    }
    @RequestMapping("/tomain")
    public String tomain(){
        return "redirect:/main";
    }
}
